<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){

        $count= M('question')->count();
        $Page       = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输
        $this->assign('show',$show);

    	$sql ="select u.face,u.nikename,c.cname,q.title,q.top,q.create_time,q.answer_num,q.view_num,q.id,q.uid from user u  join question q on u.id = q.uid  join category c on q.cid = c.id order by q.create_time desc limit ".$Page->firstRow.','.$Page->listRows;
    	$res = M()->query($sql);
    	$this->assign("res",$res);

    	var_dump($this->gettop());
    	// $this->assign('top',$top);

    	$sql ='select title,view_num,id from question order by view_num desc limit 15';
    	$hot = M()->query($sql);
    	$this->assign('hot',$hot);

        $sql ='select title,answer_num,id from question order by answer_num desc limit 15';
        $hot_ans = M()->query($sql);
        $this->assign('hot_ans',$hot_ans);

		$this->display();
    }

    public function jie()
    {	
    	$count= M('question')->count();
        $Page       = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输
        $this->assign('show',$show);

        $sql ="select u.face,u.nikename,c.cname,q.title,q.top,q.create_time,q.answer_num,q.view_num,q.id,q.uid from user u  join question q on u.id = q.uid  join category c on q.cid = c.id order by q.create_time desc limit ".$Page->firstRow.','.$Page->listRows;
        $res = M()->query($sql);
        $this->assign("res",$res);

    	$this->display();
    }

    public function unsolved()
    {
    	$count= M('question')->where("status='未结贴'")->count();
        $Page       = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输
        $this->assign('show',$show);

        $sql ="select u.face,u.nikename,c.cname,q.* from user u  join question q on u.id = q.uid  join category c on q.cid = c.id where q.status='未结贴' order by q.create_time desc limit ".$Page->firstRow.','.$Page->listRows;
        $res = M()->query($sql);
        $this->assign("res",$res);

    	$this->display('jie');
    }

    public function solved()
    {
    	$count= M('question')->where("status='已采纳'")->count();
        $Page       = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输
        $this->assign('show',$show);

        $sql ="select u.face,u.nikename,c.cname,q.* from user u  join question q on u.id = q.uid  join category c on q.cid = c.id where q.status='已采纳' order by q.create_time desc limit ".$Page->firstRow.','.$Page->listRows;
        $res = M()->query($sql);
        $this->assign("res",$res);

        $this->display('jie');
    }

   public function wonderful()
    {
    	$count= M('question')->where("top='精华'")->count();
        $Page       = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输
        $this->assign('show',$show);

        $sql ="select u.face,u.nikename,c.cname,q.* from user u  join question q on u.id = q.uid  join category c on q.cid = c.id where q.jing='精华' order by q.create_time desc limit ".$Page->firstRow.','.$Page->listRows;
        $res = M()->query($sql);
        $this->assign("res",$res);

        $this->display('jie');
    }
}